import http from "./http";
import qs from "qs";
import axios from 'axios'
import Cookie from "js-cookie";
import md5 from "js-md5";
import {decrypt} from "@/utils";
import StorageModel from "@/utils/storage";
import { AUTH } from "@/utils/constant";

const Storage = new StorageModel();

export const logout = () => {
  delete axios.defaults.headers["Authorization"];
  Storage.clear();
};

export default {
  setToken(token) {
    http.setToken(token);
  },
  setXToken(xtoken) {
    http.setXToKen(xtoken);
  },
  //获取验证吗
  captcha(random) {
    return "/openapi/captcha?randomStr=" + random;
  },
  // captcha(random) {
  //   let rtyu = "KiqdJOMcbnPL2NlixR6q7yQopjtMeBKyzSOwryI5IzM=";
  //   let hjkl = process.env.VUE_APP_KEY;
  //   let qwer = "0";
  //   let asdf = parseInt(Math.random() * 1000000);
  //   let zxcv = parseInt(new Date().getTime() / 1000);
  //   let eirn = decrypt(rtyu, hjkl);
  //   let fghj = "/biz/captcha";
  //   fghj = fghj.toLocaleLowerCase();
  //   let iop = md5(fghj + "-" + zxcv + "-" + asdf + "-" + qwer + "-" + eirn);
  //   let sign = zxcv + "-" + asdf + "-" + qwer + "-" + iop;
  //   return process.env.VUE_APP_BASEURL + "/captcha?randomStr=" + random+"&sign="+sign;
  // },
  /**
   * 退出登录，
   * @returns
   */
  logout() {
    return http.post("/member/users/logout");
  },

  // 在线人数
  getOnline() {
    return http.get("/member/o");
  },
  /**
   * 登录接口
   * @param {*} userName  用户名
   * @param {*} pwd  密码
   * @param {*} xtoken  xtoken
   * @param {*} code  验证码
   */
  login(params={}) {
    return http.post("/login", qs.stringify(params));
  },
  /**
   * 注册用户
   * @returns
   */
  register(member={}) {
    return http.post("/member/user/register", qs.stringify(member), {
      headers: {
        xtoken: member.xtoken
      }
    });
  },
  /**
   * 获取用户信息，登录后，根据cookie获取token
   * @returns
   */
  userInfomation(that) {
    return http.get("/member/user/userAmountRelated", {}, {
      cancelToken: new axios.CancelToken(function executor(c) {
        // 设置 cancel token
        that.source = c;
      })
    });
  },
  checkCaptchaOpen() {
    return http.get("/member/user/checkCaptchaOpen");
  },
  /**
   * 验证是否需要验证码登录
   * @returns
   */
  isEnableCaptcha(params={}) {
    return http.get("/isEnableCaptcha", params);
  },
  /**
   * 校验账号名是否存在
   * @returns
   */
  checkAccount(params={}) {
    return http.get("/member/user/checkAccount",params);
  },
  /**
   * 校验是否打开手机验证码
   * @returns
   */
  checkPhoneCodeOpen(params={}) {
    return http.get("/member/user/checkPhoneCodeOpen");
  },
  /**
   * 获取在线客服信息
   * @returns
   */
  getCustomerServiceInfo(params={}) {
    return http.get("/member/home/getCustomerServiceInfo",params);
  },
  /**聊天机器人是否开启关闭*/
  getRobotJump() {
    return http.get("/member/home/robotJump");
  },
  /**
   * 新 获取聊天机器人参数
   * @returns
   */
   createdJumpToken() {
    return http.post("/member/home/createdJumpToken");
  },
  /**
   * 获取有活动在线客服信息
   * @returns
   */
  getOnLineAgentUserCustomerServiceInfo(params={}) {
    return http.get("/member/home/getOnLineAgentUserCustomerServiceInfo",params);
  },
  /**
   * 获取无活动在线客服信息
   * @returns
   */
  getNoOnLineAgentUserCustomerServiceInfo(params={}) {
    return http.get("/member/home/getNoOnLineAgentUserCustomerServiceInfo",params);
  },
  /**
   * 获取个人资讯信息
   * @param {string} lotteryId
   * @returns
   */
  playGroupLimit(params={}) {
    return http.get("/member/lottery/playGroupLimit",params);
  },
  //
  /**
   *
   * 获取开奖时间 开奖信息
   * @param {*} lotteryId
   * @returns
   */
  lotteryTimes(lotteryId, that) {
    let params = {
      lotteryId
    };
    return http.get("/member/lotteryTime/info",params, {
      cancelToken: new axios.CancelToken(function executor(c) {
        // 设置 cancel token
        that.source = c;
      })
    });
  },
  // 全彩种倒计时
  allCountDown(that) {
    let params = {};
    return http.get("/member/lotteryTime/allCountDown",params, {
      cancelToken: new axios.CancelToken(function executor(c) {
        // 设置 cancel token
        that.source = c;
      })
    });
  },

  /**
   *
   * 获取可用彩种玩法和分组
   * @returns
   */
  lotteryPlay(params = {}) {
    return http.get("/member/lottery/lotteryPlay",params);
  },
  /**
   *
   * 根据彩种ID跟大玩法分组ID获取具体的下注项
   * @returns
   */
  playDetail(params = {}, that = {source: null}) {
    return http.get("/member/lottery/playDetail", params, {
      cancelToken: new axios.CancelToken(function executor(c) {
        // 设置 cancel token
        that.source = c;
      })
    });
  },
  // 根据彩种ID获取推荐的快捷下注项
  quickPlayDetail(params = {}, that) {
    return http.get("/member/lottery/quickPlayDetail",params, {
      cancelToken: new axios.CancelToken(function executor(c) {
        // 设置 cancel token
        that.source = c;
      })
    });
  },
  /**
   *
   * 根据彩种ID跟大玩法分组ID获取具体的下注项
   * @returns
   */
  betting(params = {}) {
    return http.post("/member/orderBets/betting", params);
  },
  /**
   * 检查注册页面需要展示的字段
   * @returns
   */
  checkRegister(params={}) {
    return http.get("/member/user/getRegistInfo", params);
  },
  /**
   *获取通知
   * @returns
   */
  getOnlineNotice(params={}) {
    return http.get("/member/notice/queryNoticeList",params);
  },
  /**
   * 获取所有彩种菜单
   * @returns
   */
  lotteryList(params={}) {
    return http.get("/member/lottery/lottery",params);
  },
  /**
   *彩种最新开奖结果
   */
  newOpenResult(params={}, that) {
    return http.get("/member/openResult/newest",params,{
      cancelToken: new axios.CancelToken(function executor(c) {
        // 设置 cancel token
        that.source = c;
      })
    });
  },
  /**
   *个人咨询
   */
  lotteryGroupGame(params={}) {
    return http.get("/member/lottery/lotteryGroupGame",params);
  },
  /**
   *会员VIP等级信息
   */
  queryVipList(params={}) {
    return http.get("/member/vip/queryVipList",params);
  },
  /**
   *
   * 获取支付列表
   * @param {*} params
   * @returns
   */
  rechargeChannel(params={}) {
    params={ clientCode: "wap" }
    // return http.get("/member/recharge/getRechargeList", params);
    return http.get("/member/recharge/getNewlyRechargeList", params);
  },
  /**
   *
   * 获取支付详细信息
   * @param {*} params
   * @returns
   */
  queryRechargeTypById(payId) {
    let params={payId}
    return http.get("/member/recharge/queryRechargeTypById",params);
  },

  saveRechargeHistory(params={}) {
    return http.post('/member/recharge/saveRechargeHistory', qs.stringify(params))
  },
  /**
   *
   * 提交充值接口
   * @param {*} params
   * @returns
   */
  recharge(rechargeParameterDTO) {
    let sign = md5(
      JSON.stringify(rechargeParameterDTO) + Storage.get(AUTH)
    ).toUpperCase();
    return http.post(
      "/member/recharge/saveRechargeInfo",
      rechargeParameterDTO,
      {
        headers: {
          sign: sign,
          Authorization: Storage.get(AUTH)
        }
      }
    );
  },
  /**
   *
   *  获取提款信息接口
   * @param {*} params
   */
  getMembercard(params={}) {
    return http.get("/member/draw/getWithdrawInfo",params);
  },
  /**
   *
   * 提款密码
   * @param {*} params
   * @returns
   */
  withdrawalPassword(params={}) {
    return http.post("/member/draw/checkDrawingPwd", qs.stringify(params));
  },
  /**
   *
   * 新增会员银行接口
   * @param {*} params
   * @returns
   */
  addBankCard(params={}) {
    return http.post("/member/bank/saveUserBank", params);
  },
  /**
 * 查询会员基本信息接口
 * @param
 */
  getMemberInfo(params={}) {
    return http.get('/member/info/getMemberInfo',params)
  },
  /**
   *
   * 获取银行列表
   * @param {*} params
   * @returns
   */
  listUserType(params={}) {
    return http.get("/member/bank/getTemplates",params);
  },
  /**获取银行卡列表**/
  queryUserBankList(params={}) {
    return http.get('/member/bank/queryUserBankList',params)
  },
  /**删除银行卡**/
  deleteUserBank(params={}) {
    return http.post(
      '/member/bank/deleteUserBank',
      qs.stringify(params)
    )
  },
  /**
   *
   * 获取提款状态
   * @param {*} params
   * @returns
   */
  queryTransaction(params={}) {
    return http.get("/member/trans/queryTransList",params);
  },
  /**
   *
   * 会员提款申请接口
   * @param {*} params
   * @returns
   */
  saveWithdraw(params={}) {
    let sign = md5(JSON.stringify(params) + Storage.get(AUTH));
    sign = sign.toUpperCase();
    return http.post("/member/draw/saveWithdraw", params, {
      headers: {
        sign: sign,
        Authorization: Storage.get(AUTH)
      }
    });
  },
  /**
   *查询会员反馈信息列表接口
   * @param {Number} currentPage
   * @param {Number} pageSize
   */
  queryFeedbackList(params={}) {
    return http.get("/member/feedback/queryFeedbackList",params);
  },
  /**
   *保存反馈信息
   * @param {String} content
   * @param {String} title
   */
  saveFeedback(params={}) {
    return http.post("/member/feedback/saveFeedback", qs.stringify(params));
  },
  // id充值
  checkRechargeByAmount(params={}) {
    return http.get("/member/recharge/checkRechargeByAmount",params);
  },
  // 未结明细、已结明细接口
  getSettleDataList(type, params={}) {
    return http.get(`/member/orderList/${type}`,params);
  },
  // 报表查询接口
  reportList(params={}) {
    return http.get(`/member/orderList/reportList`,params);
  },
  // 报表点击的当日注单列表
  reportDetailed(params={}) {
    return http.get(`/member/orderList/reportDetailed`,params);
  },
  getChangLongList(params={}) {
    return http.get(`/longDragon/statistics`,params);
  },
  getK3ChangLongList(params={}) {
    return http.get(`/longDragon/k3Statistics`,params);
  },
  getNumberStatistics(params={}) {
    return http.get(`/roadBead/statistics`,params);
  },
  getBallNumStatistics(params={}) {
    return http.get(`/roadBead/ballNumStatistics`,params);
  },
  // 在线充值
  pay(params={}) {
    // return http.post("/pay/pay", qs.stringify(params));
    return http.post("/pay/payNew", qs.stringify(params));
  },
  // 豪富支付回调接口
  hfCallback(params={}) {
    return http.post("/pay/hfCallback", qs.stringify(params));
  },
  //根据彩种ID获取具体的下注项
  robotPlayDetail(params={}) {
    return http.get(`/member/lottery/robotPlayDetail`,params);
  },
  //彩种对应开奖结果
  result(params={}) {
    return http.get(`/member/openResult/result`,params);
  },
  //获取彩种长龙统计
   longDragon(params={}) {
     return http.get(`/longDragon/statistics`,params);
   },
  //获取快3类彩种长龙统计
  longDragon_k3(params={}) {
    return http.get(`/longDragon/k3Statistics`,params);
  },
  //长龙投注列表
  longDragonBet(params={}) {
    return http.get(`/longDragon/longDragonBet`,params);
  },
  // 长龙下注
  longBets(params={}) {
    return http.post("/member/orderBets/longBets", params);
  },
  // 砸蛋结果
  eggsResult(params={}) {
    return http.post("/member/eggs/eggsResult", params);
  },
  // 获取砸蛋信息
  eggsInfo(params={}) {
    return http.get("/member/eggs/eggsActivitiesInfo",params);
  },
  /**
   *
   * 当前彩种未结注单接口
   * @returns
   */
  betUnSettleList(params = {}, that) {
    return http.get(
      "/member/orderList/betUnSettleList",
      params,
      {
        cancelToken: new axios.CancelToken(function executor(c) {
          // 设置 cancel token
          that.source = c;
        })
      }
    );
  },

  // 签到活动
  getSign(params={}) {
    return http.get(`/member/sign/query`, params);
  },
  // 签到接口
  setSign(params={}) {
    return http.get(`/member/sign/in`, params);
  },
  // 签到活动状态
  getSignStatus(params={}) {
    return http.get(`/member/sign/status`, params);
  },
  // 返回推荐好友活动的数据
  getUserInviteStting(params={}) {
    return http.get(`/userInvite/getUserInviteStting`, params);
  },
  // 返回推广码
  getPromotionCode(params={}) {
    return http.get(`/userInvite/getPromotionCode`, params);
  },
  // 返回推荐好友活动的统计数据
  getUserInviteStatistics(params={}) {
    return http.get(`/userInvite/getUserInviteStatistics`, params);
  },

   // 图片域名
   chatDomain() {
    return http.post("/chatDomain")
  },
  // 用户信息
  getUserInfo() {
    return http.post("/getUserInfo")
  },
   /**
   * banner 活动
   * @param
   */
   getSysAdverList(params={}) {
    return http.get("/member/home/sysAdver/getList", params)
   },
  queryConversionList(params={}) {
    // return http.get("/member/trans/queryConversionList", params);
    return http.get("/sys/userbalance/conversionRecord", params);
  },
  queryPhoneList(params={}) {
    return http.get("/member/home/sysAdver/getList", params);
  },
  // 校验接口
  openResultVerify(params={}) {
    return http.get("/member/openResult/verify", params);
  },
  // 冷热
  openResultHotcold(params={}) {
    return http.get("/member/openResult/hotcold", params);
  },
  // 遗漏
  openResultOmit(params={}) {
    return http.get("/member/openResult/omit", params);
  },
};
